<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security" xmlns:auth=""
      class="x-admin-sm">
<auth:data uri="/data/film/list.json"/>
<head>
    <th:block th:include="common/head::noXadmin('影音资源')"/>
    <style>
        tbody .layui-table-cell {
            height: 180px;
            line-height: 180px;
            text-align: center;
        }

        .film_info {
            text-align: left;
            overflow-y: scroll;
            height: 180px;
        }

        .film_name {
            position: absolute;
            left: 0px;
            line-height: 24px;
            bottom: 0px;
            text-align: center;
            background: black;
            color: white;
            right: 0;
        }

        .film_info .info_item {
            display: block;
            line-height: 24px;
            padding: 0 5px;
            word-wrap: break-word;
            word-break: break-all;
        }

        .film_info .desc {
            display: block;
            padding: 0 5px;
            white-space: normal;
            word-break: break-all;
            word-wrap: break-word;
            line-height: 24px;
        }

        .film_info span {
            font-weight: bold;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row ">
        <div class="layui-col-md12">
            <div class="layui-card" id="queryBox">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="开始日" name="stime"
                                   id="start">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="截止日" name="etime"
                                   id="end"></div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="channel" lay-verify="">
                                <option value="">频道</option>
                                <option value="电影">电影</option>
                                <option value="电视">电视</option>
                                <option value="卡通">卡通</option>
                                <option value="综艺">综艺</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="name" placeholder="请输入影音名称" autocomplete="off"
                                   class="layui-input"></div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="del" lay-verify="">
                                <option value="">状态</option>
                                <option th:each="status:${T(com.hardydou.common.constant.Const.DelStatus).values()}"
                                        th:value="${status.val}"
                                        th:text="${status.name}">
                                </option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">

                            <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                <i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>

            </div>
            <div class="layui-card">
                <div class="split-line-y split-line-y-open">
                    <i class="fa "></i>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table" id="dataList" lay-filter="data"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<th:block th:inline="none">
    <script type="text/html" id="coverTml">
        <img src="{{d.cover}}" style="width: 100px;"/>
        <span class="film_name">{{d.name}}</span>
    </script>
    <script type="text/html" id="filmInfoTml">
        <div class="film_info">
            <label class="info_item"><span>频道：</span>{{d.channel}} | <span> 类型：</span>{{d.type}} | <span>地区：</span>{{d.area}}</label>
            <label class="info_item"><span>评分：</span>{{d.score}}</label>
            <label class="info_item"><span>导演：</span>{{d.director}}</label>
            <div class="desc"><span>演员：</span>{{d.actor}}</div>
            <div class="desc"><span>简介：</span>{{d.intro}}....</div>
        </div>

    </script>
    <script id="delTml" type="text/html">
        <input type="checkbox" name="del" value="{{d.resId}}" lay-skin="switch" lay-text="下架|上架"
               {{d.del==0?"checked":""}} lay-filter="del">
    </script>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add">
                <i class="layui-icon layui-icon-add-circle "></i>添加
            </button>
        </div>
    </script>
    <script type="text/html" id="barTpl">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">下架</a>
    </script>
    <script>
        layui.use(['jquery'], function () {
            var $ = layui.jquery;
            var queryBoxShow = true;
            $(".split-line-y >i").click(function () {
                if (queryBoxShow) {
                    queryBoxShow = false;
                    $("#queryBox").slideUp('fast');
                    $(".split-line-y").removeClass('split-line-y-open').addClass('split-line-y-closed');
                } else {
                    queryBoxShow = true;
                    $("#queryBox").slideDown('fast');
                    $(".split-line-y").removeClass('split-line-y-closed').addClass('split-line-y-open');
                }

            });
        })
        layui.use(['table', 'form'],
            function () {
                var table = layui.table,
                    form = layui.form;
                table.render({
                    elem: '#dataList'
                    , toolbar: '#toolbarDemo'
                    , totalRow: false
                    , url: '/data/film/list.json' //数据接口
                    , page: true //开启分页
                    , response: {
                        statusCode: 0
                    }
                    , cols: [[
                        {checkbox: true, type: 'checkbox', fixed: 'left'}
                        , {field: 'resId', title: 'ID', width: 100, sort: true, fixed: 'left'}
                        , {field: 'cover', title: '封面', width: 150, templet: '#coverTml'}
                        , {field: '', title: '介绍', templet: '#filmInfoTml'}
                        , {field: 'del', title: '状态', width: 120, templet: '#delTml'}
                        , {field: 'udate', title: '更新日期', width: 180, sort: true}
                        , {fixed: 'right', title: '操作', width: 178, align: 'center', templet: '#barTpl'}
                    ]],
                    parseData: function (res) {
                        return {
                            code: res.code,
                            msg: res.message,
                            count: res.data.total,
                            data: res.data.list,
                            totalRow: {
                                score: "score",
                                experience: "exp"
                            }
                        }

                    }
                    , request: {
                        pageName: 'pageNum' //页码的参数名称，默认：page
                        , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                    }
                })
                form.on('switch(status)', function (data) {
                    $.ajax({
                        url: rootPath + 'system/role/status?roleId=' + data.value,
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            layer.msg(data.message);
                        },
                        error: function (data) {
                            layer.msg(data.message);
                        }
                    });
                })
                //监听工具条
                table.on('tool(data)',
                    function (obj) {
                        var data = obj.data
                            , event = obj.event //事件
                        ;
                        switch (event) {
                            case 'edit':
                                xadmin.open('修改信息', rootPath + 'data/film/edit?resId=' + data.resId)
                                break;
                            case 'detail':
                                xadmin.open('影视详情', rootPath + 'data/film/info?resId=' + data.resId)
                                break;
                            case 'del':
                                layer.msg('你确定删除么？', {
                                    time: 2000,//2秒自动关闭
                                    btn: ['确定', '取消'],
                                    yes: function (index) {
                                        $.ajax({
                                            url: rootPath + 'data/film/del?resId=' + data.resId,
                                            type: "DELETE",
                                            dataType: "json",
                                            success: function (data) {
                                                console.log(data);
                                                layer.msg(data.message);
                                                location.reload(); //删除成功后再刷新
                                            },
                                            error: function (data) {
                                                layer.msg(data.message);
                                            }
                                        });
                                        layer.close(index);
                                    }
                                })
                                break;

                        }
                    });

                //头工具栏事件
                table.on('toolbar(data)',
                    function (obj) {
                        switch (obj.event) {
                            case 'add':
                                xadmin.open('添加资源', rootPath + 'data/film/add');
                                break;
                        }
                        ;
                    });
                form.on('submit(sreach)', function (data) {
                    console.log(data.field);
                    table.reload('dataList', {
                            page: {
                                curr: 1
                            },
                            where: data.field
                        }
                    )
                    return false;
                })
                form.on('switch(del)', function (data) {
                    $.ajax({
                        url: rootPath + 'data/film/status?resId=' + data.value,
                        type: "PUT",
                        dataType: "json",
                        success: function (data) {
                            layer.msg(data.message);
                        },
                        error: function (data) {
                            layer.msg(data.message);
                        }
                    });
                })
            });</script>
    <script>layui.use('laydate',
        function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });

        });</script>
</th:block>
</html>